package org.fat.nerd.generator.main;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>description</p>
 *
 * @author TanXin
 * @since 2022/2/22 11:31
 */
public class GeneratorMain {

    public static void main(String[] args) throws Exception {
        List<String> warnings = new ArrayList<>();
        String configFilePath = GeneratorMain.class.getClassLoader().getResource("mybatis-generator.xml").getFile(); // mybatis-generator.xml 配置文件放在 resources 目录里。
        File configFile = new File(configFilePath);
        ConfigurationParser parser = new ConfigurationParser(warnings);
        Configuration config = parser.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(true); // 存在则覆盖

        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
    }
}
